package com.wxdc.nmgyt.nmgytwydc.base;

import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

/**
 * Created by Administrator on 2018/4/19.
 * 基于Rx的Presenter封装,控制订阅的生命周期
 */

public class RxPersenter<T extends BaseView> implements BasePersenter<T>  {

    protected T mView;
    protected CompositeDisposable mCompositeDisposable;

    protected void addDisposable(Disposable disposable){
        if (mCompositeDisposable == null) {
            mCompositeDisposable = new CompositeDisposable();
        }
        mCompositeDisposable.add(disposable);
    }

    protected void unDisposable(){
        if (mCompositeDisposable != null) {
            mCompositeDisposable.clear();
        }
    }

    @Override
    public void attachView(T view) {
        this.mView = view;
    }

    @Override
    public void detachView() {
        unDisposable();
        this.mView = null;
    }
}
